"""
实现一个学员管理系统，要求能够记录学员的姓名和分数。
要求能够实现，添加学员、删除学员、查询学员、以及求学员平均分数。
在查询学员的时候，如果没有查询到，则抛出异常。
"""


class StudentManage:
    def __init__(self):
        self.students = []

    # 添加学员
    def append_student(self, student):
        self.students.append(student)
        print(f"添加成功，新增的学员的姓名为：{student.name}, 分数为：{student.score}")

    # 删除学员
    def remove_student(self, name):
        for student in self.students:
            if student.name == name:
                self.students.remove(student)
                print("删除成功")
                break
    # 查询学员

    def get_student_info(self, name):
        try:
            flag = False
            for student in self.students:
                if student.name == name:
                    flag = True
                    break
            if flag:
                print(f"查询成功，新增的学员的姓名为：{student.name}, 分数为：{student.score}")
                # return student
            else:
                raise ValueError
        except ValueError:
            print("No such student found")

    # 求学员平均成绩
    def get_average_score(self):
        sum_score = 0
        for student in self.students:
            sum_score += student.score
        try:
            return sum_score / len(self.students)
        except ZeroDivisionError:
            print("不存在学生")

